<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>租金提醒用户与组织架构关系表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <table class="layout2col1">
        <tbody>
        <tr>
            <td style="width: 500px;" valign="top">
                <div  class="sqPanel">
                    <div class="sqPanel_head">
                        <form id="searchBar1" class="titSearchBar">
                            <div class="fieldset1 clearFix">
                                <div class="fieldBox">
                                    <div class="label">名称</div>
                                    <div class="field">
                                        <input name="rlNm" id="rlNm" type="text" class="ui-textbox" value="" ligerui="width: 100">
                                    </div>
                                </div>
                                <span id="searchBtn1" class="sq-search-button">查询</span>
                                <span id="clearBtn1" class="sq-search-button">清空</span>
                            </div>
                        </form>
                    </div>
                    <div class="sqPanel_body">
                        <div class="FBL5">
                            <!-- <span id="addBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_3"></i>新增</span>
                            <span id="changeBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_4"></i>修改</span>
                            <span id="inheritBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_16"></i>权限继承</span> -->
                        </div>
                        <div id="ligergrid_name" class="sq-grid"></div>
                    </div>
                </div>
            </td>
            <td style="width: 300px;" valign="top">
                <div class="sqPanel">
                    <div class="sqPanel_head">
                        <form id="searchBar2" class="titSearchBar">
                            <div class="fieldset1 clearFix">
                                <div class="fieldBox">
                                    <div class="label">资源名称</div>
                                    <div class="field">
                                        <input name="orgNm" id="orgNm" type="text" class="ui-textbox" value="" ligerui="width: 100">
                                    </div>
                                </div>
                                <span id="searchBtn2" class="sq-search-button"></i>查询</span>
                                <span id="clearBtn2" class="sq-search-button">清空</span>
                            </div>
                        </form>
                    </div>
                    <div class="sqPanel_body" style="min-height: 300px;">
                        <div class="FBL5">
                            <span id="saveBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_30"></i>保存</span>
                        </div>
                        <div class="nanoWrap" style="height: 320px;">
                            <div class="nano"><div class="nano-content">
                                <ul id="tree1">
                                </ul>
                            </div></div>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
        </tbody>
    </table>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null, callback = null, tree = null,RESOURCE_IDs=[];
    $(function () {
        grid = $("#ligergrid_name").ligerGrid({
            url: '<%=path%>/risk/rskUsrOrgR/initList.do',
            method: 'get',
            columns: [
                {display: '用户名', name: 'usrNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '真实名称', name: 'rlNm', minWidth: 100, align: 'center', enabledSort: false},
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            width: '100%',
            height: '100%',
            heightDiff: -2,
            //isScroll: false,
            checkbox: false,
            rownumbers: true,
            isSingleCheck:true,
            alternatingRow: false
        });
        grid.setHeight(100);

        $("#searchBar1").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn1").click(function (event) {
            var form = liger.get("searchBar1");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn1").click(function (event) {
            clearLigerForm("searchBar1");
        });

        callback = function () {
            grid.reload();
        };

        /* 查询2 */
        $("#searchBar2").ligerForm();

        $("#searchBtn2").click(function() {
            var form = liger.get("searchBar2");
            var data = form.getData();
            $.extend(true, data, { RESOURCE_IDs: RESOURCE_IDs});
            searchResource(data);
        });
        /* 清空 */
        $("#clearBtn2").click(function (event) {
            clearLigerForm("searchBar2");
        });
        tree = $("#tree1").ligerTree({
            url: '<%=path%>/risk/rskUsrOrgR/treeInitList.do',
            ajaxType: 'get',
            nodeWidth: 300,
            parentIcon: "SqFolder",
            childIcon: "SqLeaf",
            iconClsFieldName: "iconClass",
            enabledCompleteCheckbox: false,
            isExpand: false,
            idField:'orgCd',
            textFieldName:'orgNm',
            isLeaf: function (data) {
                if (!data) return false;
                if (data.hasChildren) {return false} else if(data.children){return false} else {return true};
            },
            onCheck: function (item,checked) {
                if (!grid.getSelectedRow()) {
                    top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_USR,SQ_type: "warning"});
                    tree.cancelSelect(item);
                    return;
                };
                SQ.setIDs_onCheckTree(item, checked, tree, RESOURCE_IDs);
            },
            onSuccess: function (data) {
                setNanoScroller();
            }
        });


        function setNanoScroller () {
            $(".nanoWrap .nano").nanoScroller({
                preventPageScrolling: true
            });
        }
        function searchResource (parm) {
            $.ajax({
                url: '<%=path%>/risk/rskUsrOrgR/treeInitList.do',
                type: 'GET',
                dataType: 'json',
                data: parm,
                success: function (result) {
                    if(result.data!=null){
                        tree.setData(result.data);
                    }else{
                        tree.reload();
                    }
                }
            });
        }
        /* 新增 租金提醒用户与组织架构关系表 */
        $("#saveBtn").click(function() {
            if (!grid.getSelectedRow()) {
                top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_USR,SQ_type: "warning"});
                return;
            };
            /*if (!tree.getChecked() ) {
             top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_ORG,SQ_type: "warning"});
             return;
             };*/
            orgCdArr=RESOURCE_IDs;
            usrId=grid.getSelectedRow().usrId;
            $.ajax({
                url: '<%=path%>/risk/rskUsrOrgR/add.do',
                type: 'post',
                dataType: 'json',
                data:{'usrId':usrId,'orgCdArr[]':orgCdArr},
                success:function(msg){
                    if(msg.success == 1){
                        top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
                    }else{
                        top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                    }
                }
            });
        });
        /* 新增 */
        $("#addBtn").click(function (event) {
            $.ligerDialog.open({
                width: 550,
                height: 500,
                title: '新增租金提醒用户与组织架构关系表',
                url: '<%=path%>/risk/rskUsrOrgR/toAddPage.do'
            });
            //Add_navTab("RskUsrOrgR_1", "新增租金提醒用户与组织架构关系表", '<%=path%>/risk/rskUsrOrgR/toAddPage.do', callback);
        });

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            $.ligerDialog.open({
                width: 550,
                height: 500,
                title: '修改租金提醒用户与组织架构关系表',
                url: '<%=path%>/risk/rskUsrOrgR/toModifyPage.do?id=' + _id
            });
            //Add_navTab('RskUsrOrgR_2'+_id, "修改租金提醒用户与组织架构关系表", '<%=path%>/risk/rskUsrOrgR/toModifyPage.do?id='+_id, callback);
        });

        /* 删除 */
        $("#delBtn").click(function () {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }

            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/risk/rskUsrOrgR/removeByIds.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });

    });

</script>

</body>
</html>
